cmake_minimum_required(VERSION 3.16)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/bin)

option(LINK_SHARED_QT "Link against shared Qt libraries" ON)

if(LINK_SHARED_QT)
    set(CMAKE_PREFIX_PATH "E:/Qt/6.9.3/mingw_64")
else()
    set(VCPKG_TARGET_TRIPLET "x64-mingw-static")
    set(VCPKG_DEFAULT_HOST_TRIPLET "x64-mingw-static")

    set(CMAKE_TOOLCHAIN_FILE "E:/vcpkg/scripts/buildsystems/vcpkg.cmake")
    set(CMAKE_PREFIX_PATH "E:/vcpkg/installed/x64-mingw-static") 
endif()

project(360  LANGUAGES CXX)

set(AUTOMOC ON)
set(AUTOUIC ON)
set(AUTORCC ON)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 REQUIRED COMPONENTS 
Widgets
OpenGLWidgets
Concurrent 
LinguistTools
)


qt_standard_project_setup()
qt_add_resources(RESOURCE_FILES qrc.qrc)
qt_add_executable(${CMAKE_PROJECT_NAME}
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
        OpenglWidget.cpp
        OpenglWidget.h
        x.ico.rc


        settings.ui 
        settings.h
        settings.cpp

        ImagePreloading.cpp
        ImagePreloading.h

        image.h
        image.cpp

        ${RESOURCE_FILES}
)


find_package(Git)
if(GIT_FOUND)
    execute_process(
        COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0
        WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
        OUTPUT_VARIABLE GIT_TAG
        OUTPUT_STRIP_TRAILING_WHITESPACE
    )
endif()
add_definitions(-DAPP_VERSION="${GIT_TAG}")


# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mconsole")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mwindows")
# target_link_options(${CMAKE_PROJECT_NAME} PRIVATE -static)

target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE
 Qt${QT_VERSION_MAJOR}::Widgets
 Qt${QT_VERSION_MAJOR}::OpenGLWidgets
 Qt${QT_VERSION_MAJOR}::Concurrent
)

#windeployqt打包qt库
if(LINK_SHARED_QT)
   add_custom_command(
    TARGET ${CMAKE_PROJECT_NAME} 
   POST_BUILD
   COMMAND ${CMAKE_PREFIX_PATH}/bin/qtenv2.bat
   COMMAND echo "${CMAKE_PREFIX_PATH}/bin/windeployqt.exe ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_PROJECT_NAME}.exe"
   COMMAND ${CMAKE_PREFIX_PATH}/bin/windeployqt.exe ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_PROJECT_NAME}.exe
    )
endif()
